<?php
App::uses('Component', 'Controller');
class FacultySubjectComponent extends Component {
	
	public function getSubIdByFaculty($facultyId){
		$this->SubFal = ClassRegistry::init('FacultiesSubject');
		return $this->SubFal->findAllBym_fct_id($facultyId);
	}
	
	public function deleteAllBySubId($subId){
		$this->SubFal = ClassRegistry::init('FacultiesSubject');
		return $this->SubFal->deleteAll(array('FacultiesSubject.sub_id' => $subId), false);
	}
	
	public function deleteAllByFacultyId($fctId){
		$this->SubFal = ClassRegistry::init('FacultiesSubject');
		$condition = array('FacultiesSubject.m_fct_id' => $fctId );
		return $this->SubFal->deleteAll($condition, false);
	}
	
	public function getRecord($factId, $subId){
		$this->SubFal = ClassRegistry::init('FacultiesSubject');
		return $this->SubFal->find('first', array('conditions' => array('FacultiesSubject.m_fct_id' => $factId, 'FacultiesSubject.sub_id' => $subId)));
	}
	
	public function addRecord($factId, $subId){
		$this->SubFal = ClassRegistry::init('FacultiesSubject');
		
		$this->SubFal->create();
		$dataNeedToSave = array('FacultiesSubject' => array('m_fct_id' => $factId,
				                'sub_id' => $subId));
		
		if($this->SubFal->save($dataNeedToSave)){
		     return $this->SubFal->id;
		}
		return 0;
	}
}
?>